<?php

function sinapp_whois($maindomain, $realtime = false) {
    $timecache = 86400 * 3;

    #Cache存放路径
    $DomainInfoCacheFile = APP_ROOT_DIR . '/data/whois-cache/sinapp-whois/' . substr(md5($maindomain), 0, 2) . '/' . $maindomain . '.txt';
    if (!$realtime && (file_exists($DomainInfoCacheFile) && time() - filemtime($DomainInfoCacheFile) < $timecache)) {
        $json = file_get_contents($DomainInfoCacheFile);
        $arrDomainInfo = json_decode($json, true);
        return $arrDomainInfo;
    }

    $api = 'http://whoisapi.sinaapp.com/?domain=' . $maindomain . '&token=0be89477816a569852a640c9ad537c10&user=user';
    $json = snoopy_fetch($api);
    $array = json_decode($json, true);
    if ($array['domain']) {
		FCheckDir($DomainInfoCacheFile);
        file_put_contents($DomainInfoCacheFile, json_encode($array));
    }
    return $array;
}

function php_sinaapp_whois($maindomain){
	$json = shell_exec('php /root/kingbin/trunk/stat/whoistools/whoisapi/1/cli.php '.$maindomain);
	$array = json_decode($json, true);
	log::n('php_whois:domain['.$maindomain.'],remaining_days['.$array['remaining_days'].'],_ipaddress['.$array['_ipaddress'].']');
	return $array;
}

?>